package com.bridgeintelligent.tag.customer.mapper;

import com.bridgeintelligent.tag.customer.entity.CustomersChannel;
import com.bridgeintelligent.tag.customer.model.ChannelQueryModel;
import com.bridgeintelligent.tag.customer.vo.ChannelVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @description
 * @author: grp 2021-02-21 23:20
 **/
@Mapper
public interface ChannelMapper {

    int add(CustomersChannel channel);

    List<ChannelVO> findList(ChannelQueryModel model);

    int update(CustomersChannel channel);

    @Delete("delete from TAG_CUSTOMERS_ISSUE_CHANNEL where id = #{id}")
    int deleteById(String id);

    ChannelVO findOne(String id);

    @Select("select count(1) from TAG_CUSTOMERS_ISSUE_CHANNEL where channel_name = #{name} and is_del = '00'")
    int countByName(String name);

    @Select("select count(1) from TAG_CUSTOMERS_ISSUE_CHANNEL where channel_id = #{id} and is_del = '00'")
    int countById(String id);

    @Select("select count(1) from TAG_CUSTOMERS_ISSUE_CHANNEL where channel_name = #{name} and channel_id <> #{id} and is_del = '00'")
    int countByNameAndNotId(String name, String id);

    @Select("select id,channel_name from TAG_CUSTOMERS_ISSUE_CHANNEL where state = '01' and is_del = '00' order by id")
    List<ChannelVO> findValidAll();

    @Select("select id,channel_name from TAG_CUSTOMERS_ISSUE_CHANNEL where is_del = '00' order by id")
    List<ChannelVO> findAll();
}
